<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link href="../static/dist/semantic.min.css" th:href="@{/dist/semantic.min.css}" rel="stylesheet">
    <!--<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>-->
    <link href="/static/css/index.css" th:href="@{/css/index.css}" rel="stylesheet">
    <link rel="stylesheet" href="../static/css/notiflix.min.css" th:href="@{/css/notiflix.min.css}">
    <style>
        body {
            height: 69vh;
            background-color: #5a6a75;
        }

        input {
            border-radius: 25px !important;
            background: #82929d !important;
            color: white !important;
        }
    </style>
</head>
<body>
<div style="max-width:30em!important;margin:15em auto!important;">
    <div class="ui container">
        <div class="ui middle aligned center grid">
            <div class="column">
                <h2 class="ui teal image header">
                    <!--<img src="assets/images/logo.png" class="image">-->
                    <div class="content">
                        <i class="balance scale icon"></i>sign in
                    </div>
                </h2>
                <form class="ui large form" onsubmit="return false" autocomplete="off">
                    <div class="stacked segment">
                        <div class="field">
                            <div class="ui left icon input">
                                <i class="user icon"></i>
                                <input type="text" name="username" id="username" placeholder="username" autofocus>
                            </div>
                        </div>
                        <div class="field">
                            <div class="ui left icon input">
                                <i class="lock icon"></i>
                                <input type="password" name="password" id="password" placeholder="password">
                            </div>
                        </div>
                        <div class="ui fluid large teal submit button" id="login">登录</div>
                    </div>
                    <!--                    <p style="color: red;"><span class="rep-text"></span></p>-->
                </form>
            </div>
        </div>
    </div>
</div>
<script src="../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
<!--<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>-->
<script src="../static/dist/semantic.min.js" th:src="@{/dist/semantic.min.js}"></script>
<script src="../static/js/notiflix.min.js" th:src="@{/js/notiflix.min.js}"></script>
<script src="../static/js/notiflix-aio.min.js" th:src="@{/js/notiflix-aio.min.js}"></script>
<script src="../static/js/public.js" th:src="@{/js/public.js}"></script>
<script>
    // function playMusic() {
    //     let music=document.getElementById("music");
    //     music.play();//移除事件
    //     document.removeEventListener('click', playMusic);
    // }
    // document.addEventListener('click', playMusic);
</script>
<script th:inline="javascript">
    $('.ui.dropdown').dropdown({
        on: 'hover'
    });
    //表单验证
    $('.ui.form').form({
        inline: true,
        keyboardShortcuts: false,
        on: 'submit',
        fields: {
            username: {
                identifier: 'username',
                rules: [
                    {
                        type: 'empty',
                        prompt: '请输入用户名'
                    }
                ]
            },
            password: {
                identifier: 'password',
                rules: [
                    {
                        type: 'empty',
                        prompt: '请输入密码'
                    }
                ]
            }
        },
        onSuccess: function () {
            login();
        }
    });
    $(document).keydown(function (event) {
        if (event.which===13){
            $('#login').submit();
        }
    });
    function login() {
        $.post({
            url: '/api/doLogin',
            data: {
                "username": $('#username').val(),
                "password": $('#password').val()
            },
            success: function (result) {
                switch (result.status) {
                    case 200:
                        window.localStorage.setItem("Authorization", "Bearer " + result.data);
                        window.location.href = ("/index/none/main");
                        break;
                    default:
                        failure(result.msg);

                }
            }
        })
    }
</script>
</body>
</html>